<?php
include '../../../wp-blog-header.php';
$city_name = $_GET['city'];
$deal = new Pod('deal');
$deal->search = false;

if(empty($city_name)){
$city_name = 'Mumbai';
}
$where = "camp_cat.url = 'c-restaurants-clubs-offers' AND t.sale = 1 AND city.name='$city_name' AND t.camp_end > ".fix_date();

$deal->findRecords('RAND()',5,$where);
$dealsFound = $deal->getTotalRows();

if($dealsFound > 0){
$op = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title></title> 
   
  <style type="text/css">
    body{
    background-color: #ffffff;
    width:520px;
    margin:0;
    padding:0; 
    border:0;
    overflow: hidden;
    }
    .deal{
    width: 480px;
    height: 130px;
    background-color: #ffffff;
    position: relative;
    margin-bottom: 5px;
    }
    
    .image{
    margin-top: 5px;
    margin-left: 5px;
    position: absolute;
    width:120px;
    height:120px;
    top: 0px;
    left: 0px; 
    
    }
    
    * html .image img{ 
    width: expression( document.body.clientWidth > 119 ? "120px" : "auto" ); /* sets max-width for IE */
     }
         
    .image img{
     border: 1px solid #DBDBCC;
     max-width: 120px;
     max-height: 120px;
    
    }
 
    .title{
    margin-top: 5px;
    width: 345px;
    height: 120px;
    position: absolute;
    top: 0px;
    right: 0px; 
   
    }
    
    .title a{
    text-decoration: none;
    font: bold 15px Arial, Helvetica, sans-serif;
    color: #000000;
    }
    
    .lastPage{
    display: none;
    }
    
    .prevPage{
    display: none;    
    }
    
    .pageNum{
     display: none; 
    }
    
    .podPaginate {
    
    margin-top:0px;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    padding:0.8em;
    overflow:hidden;
    border-top:1px solid #eee;
    background:#f6f6f6;
    color:#666;
    margin-bottom:0.8em;
    width: 300px;
    }
    
    .firstPage{
    font: 12px Arial, Helvetica, sans-serif;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    text-decoration: none;
    border: 1px solid #000000;
    background-color: #3B5998;
    color: #ffffff;
    padding: 2px 3px 2px 3px;
    
    }
    
    .nextPage{
    font: 12px Arial, Helvetica, sans-serif;
    -moz-border-radius:10px;
    -webkit-border-radius:10px;
    text-decoration: none;
    border: 1px solid #000000;
     background-color: #3B5998;
    color: #ffffff;
    padding: 2px 3px 2px 3px;
    }
    
    a:hover{
    background-color: #314A7E;
    }
  </style>
  </head>
  <body>';
        $op.= 'Choose a different City:<select name="city_select" onchange="window.location.href = this.value;">';
        $city_pod = new Pod('city');
        $city_pod->page = 1;
        $city_pod->search = false;
        $city_pod->findRecords('name ASC', -1);
        while($city_pod->fetchRecord()){
         $citname = $city_pod->get_field('name');
         /* Checks for the Selected City to show as Selected in DropDown else populates other options */
          if($city_name == $citname){
            $op.= '<option selected="selected" value="http://buzzr.in/wordpress/wp-content/plugins/buzzr_facebook/fb_mumbai_rest.php?city='.$citname.'">'.$citname.'</option>';
          }
          else{
            $op.= '<option value="http://buzzr.in/wordpress/wp-content/plugins/buzzr_facebook/fb_mumbai_rest.php?city='.$citname.'">'.$citname.'</option>';
          }          
         /* Checks for the Selected City to show as Selected in DropDown */
        }
    	  $op.= '</select>';
while($deal->fetchRecord()){
  $title = stripslashes($deal->get_field('name'));
  $image_url = $deal->get_field('image.guid');
  if(empty($image_url)){
    $image_url = $deal->get_field('ext_image_url');
  }
  $link = get_bloginfo('url').'/deals/'.$deal->get_field('camp_link').'?utm_source=fbbuzzrMumbai&utm_medium=facebook&utm_campaign=restaurant+offers';
    
   if(!empty($image_url)){ 
   $op.= '<div class="deal">   
      
      
      <div class="image">
        <a href="'.$link.'" target="_blank"><img src="'.$image_url.'" /></a>
      </div>
      
      <div class="title"><a href="'.$link.'" target="_blank">
      '.$title.'
      </a></div>
    </div>';
  }  
}

echo $op;
$deal->getPagination();
}
else{
  $op.= 'Choose a different City:<select name="city_select" onchange="window.location.href = this.value;">';
        $city_pod = new Pod('city');
        $city_pod->page = 1;
        $city_pod->search = false;
        $city_pod->findRecords('name ASC', -1);
        while($city_pod->fetchRecord()){
         $citname = $city_pod->get_field('name');
         /* Checks for the Selected City to show as Selected in DropDown else populates other options */
          if($city_name == $citname){
            $op.= '<option selected="selected" value="http://buzzr.in/wordpress/wp-content/plugins/buzzr_facebook/fb_mumbai_rest.php?city='.$citname.'">'.$citname.'</option>';
          }
          else{
            $op.= '<option value="http://buzzr.in/wordpress/wp-content/plugins/buzzr_facebook/fb_mumbai_rest.php?city='.$citname.'">'.$citname.'</option>';
          }          
         /* Checks for the Selected City to show as Selected in DropDown */
        }
    	  $op.= '</select>';
    	  $op.=  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title></title>
  </head>
  <body>
    <p><b>Sorry, no Active offers in this City</b></p>
  </body>
  </html>'; 
    	  echo $op;
}
?>